package com.oracle.lingshangejia.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.bean.TakingRecordsBean;

import java.util.List;

public class TakingRecordsAdapter extends RecyclerView.Adapter<TakingRecordsAdapter.ViewHolder> {

    private Context context;
    private OnItemClickListener onItemClickListener;
    private List<TakingRecordsBean.DataBean> data;
    public interface  OnItemClickListener{
        void onItemClick(View view, int postion);
    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public TakingRecordsAdapter(Context context, List<TakingRecordsBean.DataBean> data){
        this.data=data;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_takingrecords,null);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        viewHolder.tv_takingrecord_name.setText(data.get(i).getJmxm());
        viewHolder.tv_takingrecords_bh.setText(data.get(i).getDabh());
        if (data.get(i).getStatus() ==1){
            viewHolder.tv_status.setText("未会诊");
        }else {
            viewHolder.tv_status.setText("已完成");
        }


        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener!=null) {
                    onItemClickListener.onItemClick(viewHolder.itemView,i);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return data.size()!=0?data.size():0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_takingrecord_name;
        TextView tv_takingrecords_bh;
        TextView tv_status;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_takingrecord_name=itemView.findViewById(R.id.tv_takingrecord_name);
            tv_takingrecords_bh=itemView.findViewById(R.id.tv_takingrecords_bh);
            tv_status = itemView.findViewById(R.id.tv_status);
        }
    }
}
